var XFApp = {};
XFApp.client = function(path){
	//编写公共服务
};
XFApp.client.prototype = {
		
		
		/**
		 * 格式化时间串
		 * @param val
		 */
		formateTime : function(value){
			
			if(!!value){
				return value.year+"-"+value.monthValue+"-"+value.dayOfMonth+" "+value.hour+":"+value.minute+":"+value.second;
			}
			return "";			
		},
		
		/**
		 * 月份翻译英文简写
		 * @param month
		 * @returns {String}
		 */
		monthConvert : function (month) {
    		if(!month){
    			return "";
    		}
    		
    		var translate = "未知类型("+month+")";
    		
    		if(month == '1' || month == '01')
    			translate = 'Jan' ;
    		else if(month == '2' || month == '02')
    			translate = 'Feb' ;
    		else if(month == '3' || month == '03')
    			translate = 'Mar' ;
    		else if(month == '4' || month == '04')
    			translate = 'Apr' ;
    		else if(month == '5' || month == '05')
    			translate = 'May' ;
    		else if(month == '6' || month == '06')
    			translate = 'Jun' ;
    		else if(month == '7' || month == '07')
    			translate = 'Jul' ;
    		else if(month == '8' || month == '08')
    			translate = 'Aug' ;
    		else if(month == '9' || month == '09')
    			translate = 'Sep' ;
    		else if(month == '10')
    			translate = 'Oct' ;
    		else if(month == '11')
    			translate = 'Nov' ;
    		else 
    			translate = 'Dec' ;
    		
    		return translate ;    		
    	},
		
		/**
		 * 
		 * @param str
		 * @param length
		 * @returns string
		 * @description 截取指定长度字符串 默认10
		 */
		subString : function(str , length){
			if(undefined == length){
				length = 12;
			}
			if(null == str || str.trim().length <= 0){
				return "";
			}
			str = str.trim();
			if(str.length <= length){
				return str;
			}
			return str.substr(0 , length)+"...";
		},
	/**
	 * 去除字符串左右空格,如果是null,NULL,Null......则返回空白
	 * @returns
	 */
	getString : function (str) {
		if(null == str
			|| str.trim().length < 1
				|| "NULL" == str.toUpperCase().trim()){
			return "";
		}
		return str.trim();
	},
	/**
	 * 格式化金额 例如999,89.89
	 * @param s 金额
	 * @param n 保留小数位数
	 * @returns {String}
	 */
	fmoney : function(s, n){   
	   n = n > 0 && n <= 20 ? n : 2;   
	   s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";   
	   var l = s.split(".")[0].split("").reverse(),   
	   r = s.split(".")[1];   
	   t = "";   
	   for(i = 0; i < l.length; i ++ )   
	   {   
	      t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");   
	   }   
	   return t.split("").reverse().join("") + "." + r;   
	},
	/**
	 * 获取url参数
	 * @param name
	 * @returns
	 */
	getUrlQueryString : function(name) {
	    	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	    	var r = window.location.search.substr(1).match(reg);
	    	if (r != null) return unescape(r[2]); return null;
	    }, 
	
	
	//设置cookie
	setCookie : function(cname, cvalue, exdays,path) {
	    var d = new Date();
	    d.setTime(d.getTime() + (exdays*24*60*60*1000));
	    var expires = "expires="+d.toUTCString();
	    var pathStr = "path="+path;
	    if(!!path){
	    	document.cookie = cname + "=" + cvalue + "; " + expires +";"+pathStr;
	    }else{
	    	document.cookie = cname + "=" + cvalue + "; " + expires;
	    }
	},
	//获取cookie
	getCookie : function(cname) {
	    var name = cname + "=";
	    var ca = document.cookie.split(';');
	    for(var i=0; i<ca.length; i++) {
	        var c = ca[i];
	        while (c.charAt(0)==' ') c = c.substring(1);
	        if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
	    }
	    return "";
	},
	//清除cookie  
	clearCookie:function(name,path) {  
		this.setCookie(name,"",-1,path);
	},
	

	getQueryString : function(name)
	{
	     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	     var r = window.location.search.substr(1).match(reg);
	     if(r!=null)return  unescape(r[2]); return null;
	}
};

/**
 * 去除字符串左右空格
 * 为了兼容IE
 */
String.prototype.trim = function () {
	return this .replace(/^\s\s*/, '' ).replace(/\s\s*$/, '' );
};
/**
 * 
 * @param str
 * @param length
 * @returns string
 * @description 截取指定长度字符串 默认10
 */
String.prototype.subString = function(str , length){
	if(undefined == length){
		length = 12;
	}
	if(null == str || str.trim().length <= 0){
		return "";
	}
	str = str.trim();
	if(str.length <= length){
		return str;
	}
	return str.substr(0 , length)+"...";
};
/**
 * 去除字符串左右空格,如果是null,NULL,Null......则返回空白
 * @returns
 */
String.prototype.getString = function (str) {
	if(null == str
		|| str.trim().length < 1
			|| "NULL" == str.toUpperCase().trim()){
		return "";
	}
	return str.trim();
};
/** 
 * 时间对象的格式化; 
 */
Date.prototype.format = function(format) {
	/* 
	 * eg:format="yyyy-MM-dd hh:mm:ss"; 
	 */
	var o = {
		"M+" : this.getMonth() + 1, // month  
		"d+" : this.getDate(), // day  
		"h+" : this.getHours(), // hour  
		"m+" : this.getMinutes(), // minute  
		"s+" : this.getSeconds(), // second  
		"q+" : Math.floor((this.getMonth() + 3) / 3), // quarter  
		"S" : this.getMilliseconds()
	// millisecond  
	};
	if (/(y+)/.test(format)) {
		format = format.replace(RegExp.$1, (this.getFullYear() + "")
				.substr(4 - RegExp.$1.length));
	}
	for ( var k in o) {
		if (new RegExp("(" + k + ")").test(format)) {
			format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
					: ("00" + o[k]).substr(("" + o[k]).length));
		}
	}
	return format;
	
};

